package com.jinmdz.fmis.dao.dao;

import com.jinmdz.fmis.dao.dao.provider.SearchOverviewProvider;
import com.jinmdz.fmis.dao.model.search.businessoverview.OverviewArrivedCountItem;
import com.jinmdz.fmis.dao.model.search.businessoverview.OverviewEquipmentCountItem;
import com.jinmdz.fmis.dao.model.search.businessoverview.OverviewFurnaceCountItem;
import com.jinmdz.fmis.dao.model.search.businessoverview.OverviewHallCountItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;
import java.util.Date;

/**
 * 殡仪馆业务总览Dao
 *
 * @author GuanKui
 * @date 2020/2/24 15:10
 */
public interface SearchOverviewDao {

    /**
     * 统计从某日开始到馆逝者
     *
     * @param arrivedDate 到馆日期
     * @return
     * @author GuanKui
     * @date 2020/2/27  14:11
     */
    @Select(" select DATE(arrived_time) as arrived_date,COUNT(*) as arrived_count from funeral_dead where as_arrived = 1 and arrived_time is not null" +
            " and deleted = 0 and DATE(arrived_time) >= #{arrivedDate,jdbcType=DATE} " +
            " group by DATE(arrived_time)")
    ArrayList<OverviewArrivedCountItem> listOverviewArrivedCountByArrivedDate(@Param("arrivedDate") Date arrivedDate);

    /**
     * 统计冷柜冷藏情况
     *
     * @param outState 出藏状态
     * @return
     * @author GuanKui
     * @date 2020/2/27  15:26
     */
    @SelectProvider(type = SearchOverviewProvider.class, method = "getOverviewEquipmentCount")
    OverviewEquipmentCountItem getOverviewEquipmentCount(@Param("outState") Integer outState);

    /**
     * 统计礼厅情况
     *
     * @param outState 出厅状态
     * @param inState  入厅状态
     * @return
     * @author GuanKui
     * @date 2020/2/27  15:26
     */
    @SelectProvider(type = SearchOverviewProvider.class, method = "getOverviewHallCount")
    OverviewHallCountItem getOverviewHallCount(@Param("outState") Integer outState, @Param("inState") Integer inState);

    /**
     * 统计各火化炉类型某日预约火化数量
     *
     * @param appointmentDate 当前日期
     * @return
     * @author GuanKui
     * @date 2020/2/27  15:26
     */
    @Select(" select furnace_type_code,COUNT(*) as appointment_count from cremation " +
            " where deleted = 0 and as_active = 1 " +
            " and DATE(appointment_date) = #{appointmentDate,jdbcType=DATE}" +
            " group by furnace_type_code")
    ArrayList<OverviewFurnaceCountItem> listOverviewFurnaceCountByAppointmentDate(@Param("appointmentDate") Date appointmentDate);
}
